﻿using System;
using System.Data;
using System.Collections.Generic;
using ZHDJ.MobileInterface.Common;

namespace ZHDJ.MobileInterface
{
    public partial class GetATMMassage : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            GetATMMassageOutParam result = new GetATMMassageOutParam();
            GetATMMassageInParam param = new GetATMMassageInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as GetATMMassageInParam;
                if (string.IsNullOrEmpty(param.TakeID) || string.IsNullOrEmpty(param.SaveID))
                {
                    result.code = "0";
                    result.desc = "求助ID与捐助ID均不能为空！";
                }

                if (isFlag)
                {
                    DataTable dtSave = ATMMassageCS.QuerySaveInfo(param.SaveID);
                    DataTable dtTake = ATMMassageCS.QueryTakeInfo(param.TakeID);
                    if (dtSave.Rows.Count > 0)
                    {
                        if (dtSave.Rows[0]["Titular"].ToString().Equals("0"))
                        {
                            result.CreatebySaveName = "捐助人：";
                            result.CreatebySave = dtSave.Rows[0]["CreateByName"].ToString() + "[" + dtSave.Rows[0]["BranchName"].ToString() + "]";
                        }
                        else if (dtSave.Rows[0]["Titular"].ToString().Equals("1"))
                        {
                            result.CreatebySaveName = "捐助组织：";
                            result.CreatebySave = dtSave.Rows[0]["BranchName"].ToString();
                            result.BranchContactPersonSave = dtSave.Rows[0]["BranchContactPerson"].ToString();
                        }
                        else
                        {
                            result.CreatebySaveName = "捐助人：";
                            result.CreatebySave = "匿名";
                        }
                        result.CreateTimeSave = Convert.ToDateTime(dtSave.Rows[0]["CreateTime"].ToString()).ToString("yyyy-MM-dd");
                        result.DescriptionSave = dtSave.Rows[0]["Description"].ToString();
                        result.NameSave = dtSave.Rows[0]["Name"].ToString();
                        result.PurposesDescriptionSave = dtSave.Rows[0]["PurposesDescription"].ToString();
                        result.ThingCountSave = dtSave.Rows[0]["ThingCount"].ToString();
                        result.PurposesSave = dtSave.Rows[0]["PurposesName"].ToString();
                        result.StatusSave = dtSave.Rows[0]["StatusName"].ToString();
                        result.ThingTypeSave = dtSave.Rows[0]["ThingTypeName"].ToString();
                        result.TitularSave = dtSave.Rows[0]["TitularName"].ToString();
                        result.EndTimeSave = Convert.ToDateTime(dtSave.Rows[0]["EndTime"].ToString()).ToString("yyyy-MM-dd");
                    }




                    if (dtTake.Rows.Count > 0)
                    {
                        result.CreatebyTakeName = "求助人";
                        result.CreatebyTake = dtTake.Rows[0]["CreateByName"].ToString() + "[" + dtTake.Rows[0]["CreateByBranchName"].ToString() + "]";
                        result.Title = dtTake.Rows[0]["Name"].ToString();
                        result.CreateTimeTake = Convert.ToDateTime(dtTake.Rows[0]["CreateTime"].ToString()).ToString("yyyy-MM-dd");
                        result.DescriptionTake = dtTake.Rows[0]["Description"].ToString();
                        result.NameTake = dtTake.Rows[0]["Name"].ToString();
                        result.ThingCountTake = dtTake.Rows[0]["ThingCount"].ToString();
                        result.StatusTake = dtTake.Rows[0]["StatusName"].ToString();
                        result.ThingTypeTake = dtTake.Rows[0]["ThingTypeName"].ToString();
                        result.EndTimeTake = Convert.ToDateTime(dtTake.Rows[0]["EndTime"].ToString()).ToString("yyyy-MM-dd");
                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetATMMassage", SerializeHelper.JsonSerializer<GetATMMassageInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<GetATMMassageInParam, GetATMMassageOutParam>();
            else
                SafeProcessRequest<GetATMMassageInParam, GetATMMassageOutParam>();
        }
    }

    #region 请求参数
    public class GetATMMassageInParam
    {
        public string SaveID
        { get; set; }

        public string TakeID
        { get; set; }
    }
    #endregion


    #region 结果参数
    public class GetATMMassageOutParam
    {
        public GetATMMassageOutParam()
        {
            code = "1";
            desc = "操作成功";
        }

        public string code
        { get; set; }

        public string desc
        { get; set; }
        /// <summary>
        /// 捐助组织or捐助人
        /// </summary>
        public string CreatebySaveName
        { get; set; }
        /// <summary>
        /// 组织名称or匿名
        /// </summary>
        public string CreatebySave
        { get; set; }
        /// <summary>
        /// 捐助联系人
        /// </summary>
        public string BranchContactPersonSave
        { get; set; }
        /// <summary>
        /// 捐助时间
        /// </summary>
        public string CreateTimeSave
        { get; set; }
        /// <summary>
        /// 捐助描述
        /// </summary>
        public string DescriptionSave
        { get; set; }
        /// <summary>
        /// 捐助名称
        /// </summary>
        public string NameSave
        { get; set; }
        /// <summary>
        /// 捐助用途说明
        /// </summary>
        public string PurposesDescriptionSave
        { get; set; }
        /// <summary>
        /// 捐助数量
        /// </summary>
        public string ThingCountSave
        { get; set; }
        /// <summary>
        /// 捐助资助用途
        /// </summary>
        public string PurposesSave
        { get; set; }
        /// <summary>
        /// 捐助状态
        /// </summary>
        public string StatusSave
        { get; set; }
        /// <summary>
        /// 捐助类型
        /// </summary>
        public string ThingTypeSave
        { get; set; }
        /// <summary>
        /// 捐助名义
        /// </summary>
        public string TitularSave
        { get; set; }
        /// <summary>
        /// 捐助有效期
        /// </summary>
        public string EndTimeSave
        { get; set; }


        /// <summary>
        /// 求助人
        /// </summary>
        public string CreatebyTakeName
        { get; set; }
        /// <summary>
        /// 求助人名字
        /// </summary>
        public string CreatebyTake
        { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title
        { get; set; }
        /// <summary>
        /// 求助时间
        /// </summary>
        public string CreateTimeTake
        { get; set; }
        /// <summary>
        /// 求助描述
        /// </summary>
        public string DescriptionTake
        { get; set; }
        /// <summary>
        /// 求助名称
        /// </summary>
        public string NameTake
        { get; set; }
        /// <summary>
        /// 求助数量
        /// </summary>
        public string ThingCountTake
        { get; set; }
        /// <summary>
        /// 求助状态
        /// </summary>
        public string StatusTake
        { get; set; }
        /// <summary>
        /// 求助类型
        /// </summary>
        public string ThingTypeTake
        { get; set; }
        /// <summary>
        /// 求助有效期
        /// </summary>
        public string EndTimeTake
        { get; set; }
    }
    #endregion
}